// 以下代码已经废弃, 已经从package.json中移除了
// "server": "node server.js",
// 用webpack自带的dev server

const express = require('express');
const webpack = require('webpack');
const webpackMiddleware = require("webpack-dev-middleware");
const webpackConf = require('./webpack.config.js');
// 在node中直接使用webpack
const compiler = webpack(webpackConf);
const app = express();

// 生成一个与webpack的compiler绑定的中间件, 然后在express启动的服务app中调用这个中间件, 其输出的文件存在于内存中
app.use(webpackMiddleware(compiler, {
  publicPath: webpackConf.output.publicPath,
}));

app.listen(3000, () => console.log('server is running'));